import java.awt.Graphics;
import java.util.HashMap;


public abstract class Person implements Drawable, Comparable{
	
	private int x;
	private int y;
	private int x_offset;
	private int y_offset;
	private HashMap<String, Animation> animations;
	private Animation currentAnimation;
	private int speed, stepsTaken = 0;
	private boolean isMoving;
	
	@Override
	public void draw(Graphics g) {
		g.drawImage(getCurrentAnimation().getCurrentFrame().getImage(), (this.getX()*OurApplet.TILE_SIZE)+ this.getXOffset(), (this.getY()*OurApplet.TILE_SIZE) + this.getYOffset(), null, null);
	}
	
	//Setters
	public void setX(int x)
	{
		this.x = x;
	}
	
	public void setY(int y)
	{
		this.y = y;
	}
	
	public void setXOffset(int x)
	{
		this.x_offset = x;
	}
	
	public void setYOffset(int y)
	{
		this.y_offset = y;
	}
	
	public void setSpeed(int speed)
	{
		this.speed = speed;
	}
	
	public void setCurrentAnimation(String s)
	{
		this.currentAnimation = this.animations.get(s);
	}
	
	public void setAnimations(HashMap<String, Animation> h)
	{
		this.animations = h;
	}
	
	//Getters
	public int getX()
	{
		return this.x;
	}
	
	public int getY()
	{
		return this.y;
	}
	
	public int getXOffset()
	{
		return this.x_offset;
	}
	
	public int getYOffset()
	{
		return this.y_offset;
	}
	
	public int getSpeed()
	{
		return this.speed;
	}
	
	public HashMap<String, Animation> getAnimations()
	{
		return this.animations;
	}
	
	public Animation getCurrentAnimation()
	{
		return this.currentAnimation;
	}
	
	public void move(int dir) {
		isMoving = true;
		stepsTaken++;
		switch (dir) {
		case 1 :
			if (stepsTaken == 10) {
				x++;
				x_offset = 0;
				isMoving = false;
				stepsTaken = 0;
			}
			else {
				x_offset = (int) (stepsTaken*OurApplet.TILE_SIZE/((double) 10));
			}
			break;
		case 2 :
			if (stepsTaken == 10) {
				y--;
				y_offset = 0;
				isMoving = false;
				stepsTaken = 0;
			}
			else {
			y_offset = (int) (-1*stepsTaken*OurApplet.TILE_SIZE/((double) 10));
			}
			break;
		case 3 :
			if (stepsTaken == 10) {
				x--;
				x_offset = 0;
				isMoving = false;
				stepsTaken = 0;
			}
			else {
			x_offset = (int) (-1*stepsTaken*OurApplet.TILE_SIZE/((double) 10));
			}
			break;
		case 4 :
			if (stepsTaken == 10) {
				y++;
				y_offset = 0;
				isMoving = false;
				stepsTaken = 0;
			}
			else {
			y_offset = (int) (1*stepsTaken*OurApplet.TILE_SIZE/((double) 10));
			}
			break;
		}
		//System.out.println("Moving: " + dir + " x: " + x + " x_offset: " + x_offset + " y: " + y + " y_offset: " + y_offset);
		
	}
	
	public boolean getMoving() {
		return isMoving;
	}
	
	@Override
	public int compareTo(Object that) {
		if (that instanceof WallTile){
			return this.getY() - ((WallTile)that).getY();
		} else {
			return this.getY() - ((Person)that).getY();
		}
	}
}
